﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Org.LyrcsoftFramework.Cloud.Core.Provider
{
    /// <summary>
    /// 默认的服务提供者实现（代码从.NET Core迁移过来之后没有IOC的默认容器）
    /// </summary>
    public class DefaultFeignServiceProvider : IServiceProvider
    {
        private readonly Dictionary<Type, Object> _services = new Dictionary<Type, Object>();

        public void RegisterService<T>(T service)
        {
            Type typeInfo = typeof(T);
            if (!_services.ContainsKey(typeInfo))
            {
                _services[typeInfo] = service;
            }
        }

        public void RegisterService(Type typeInfo, Object service)
        {
            if (!_services.ContainsKey(typeInfo))
            {
                _services[typeInfo] = service;
            }
        }

        public object GetService(Type serviceType)
        {
            if (_services.TryGetValue(serviceType, out var service))
            {
                return service;
            }
            return null;
        }
    }
}
